"""
RedFlag-TC000039   视频与拍照切换检查
视频与拍照之间进行来回点击切换场景
视频与拍照之间进行来回滑动切换场景
"""
__author__ = "ldm"

import sys
import os
# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *
auto_setup(__file__)

shooter = CameraVideoShooter()

log("---------------------------------前置用例场景-------------------------------------")
"""
进去相机拍摄
对拍照页面进行截屏
对视频页面进行截屏
"""
shooter.enter_photograph()
sleep(2.0)
video_page_screenshot = shooter.capture_screenshot(file_name="TC000039A.png")
shooter.click_element(shoot_page_pictures)
photo_page_screenshot = shooter.capture_screenshot(file_name="TC000039B.png")


log("--------------------------视频与拍照之间进行来回点击切换场景-----------------------------")
"""
循环切换视频和拍照
判断断言
"""

for _ in range(10):
            shooter.click_element(shoot_page_video)
            shooter.assert_image_exists(video_page_screenshot, "断言失败，图片比对不成功")

            shooter.click_element(shoot_page_pictures)
            shooter.assert_image_exists(photo_page_screenshot, "断言失败，图片比对不成功")


log("--------------------------视频与拍照之间进行来回点击切换场景-----------------------------")
"""
进行滑动切换
判断断言
"""
for _ in range(10):
    shooter.swipe_screen((0.75, 0.6), (0.2, 0.6), duration=0.3)
    shooter.assert_image_exists(photo_page_screenshot, "断言失败，图片比对不成功")

    shooter.swipe_screen((0.2, 0.6), (0.75, 0.6),duration=0.3)
    shooter.assert_image_exists(video_page_screenshot, "断言失败，图片比对不成功")

# 关闭应用
stop_app(UGC_package_name)